﻿namespace Hidistro.UI.Web.pay
{
    using Hidistro.ControlPanel.Sales;
    using Hidistro.Core;
    using Hidistro.Entities.Orders;
    using System;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Xml;

    public class app_alipay_Submit : Page
    {
        protected HtmlHead Head1;
        public string pay_json = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            string str = base.Request.QueryString.Get("orderId");
            if (!string.IsNullOrEmpty(str))
            {
                OrderInfo orderInfo = OrderHelper.GetOrderInfo(str);
                if (orderInfo != null)
                {
                    string xml = HiCryptographer.Decrypt(SalesHelper.GetPaymentMode("hishop.plugins.payment.ws_apppay.wswappayrequest").Settings);
                    XmlDocument document = new XmlDocument();
                    document.LoadXml(xml);
                    StringBuilder builder = new StringBuilder();
                    builder.Append("partner=\"");
                    builder.Append(document.GetElementsByTagName("Partner")[0].InnerText);
                    builder.Append("\"&out_trade_no=\"");
                    builder.Append(orderInfo.OrderId);
                    builder.Append("\"&subject=\"");
                    builder.Append("订单支付");
                    builder.Append("\"&body=\"");
                    builder.Append("订单号-").Append(orderInfo.OrderId);
                    builder.Append("\"&total_fee=\"");
                    builder.Append(orderInfo.GetTotal().ToString("F0"));
                    builder.Append("\"&notify_url=\"");
                    builder.Append(Globals.UrlEncode(Globals.FullPath("/pay/app_alipay_notify_url.aspx")));
                    builder.Append("\"&service=\"mobile.securitypay.pay");
                    builder.Append("\"&_input_charset=\"UTF-8");
                    builder.Append("\"&return_url=\"");
                    builder.Append(Globals.UrlEncode("http://m.alipay.com"));
                    builder.Append("\"&payment_type=\"1");
                    builder.Append("\"&seller_id=\"");
                    builder.Append(document.GetElementsByTagName("Seller_account_name")[0].InnerText);
                    builder.Append("\"&it_b_pay=\"1m\"");
                    string str3 = Globals.UrlEncode(RSAFromPkcs8.sign(builder.ToString(), document.GetElementsByTagName("Key")[0].InnerText, "utf-8"));
                    this.pay_json = builder.ToString() + "&sign=\"" + str3 + "\"&sign_type=\"RSA\"";
                }
            }
        }
    }
}

